import userService from "../service/UserService";

/**
 * 用户登录信息
 */
export default {
    namespaced: true,
    state: {
        data: null
    },
    getters: {
        /**
         * 用户是否已登录
         */
        isLogged(state) {
            return state.data !== null;
        }
    },
    mutations: {
        login(state, user) {
            state.data = user;
        },
        logout(state) {
            state.data = null;
        }
    },   
    actions: {
        getLoginUser(context) {
            userService.getLoginUser().then(user => context.commit('login', user));
        }
    }
}